package videoCourse.sort;

import java.util.Arrays;

public class MyInsertSort {
    public static void main(String[] args) {
        int[] arr = new int[]{3,2,5,10,4,6,7,9,8};

        insertSoor(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void insertSoor(int[] arr) {
        for(int i = 1;i<arr.length;i++){
            if(arr[i] < arr[i-1]){
                int temp = arr[i];
                int j;
                for(j = i-1;j>=0 && arr[j] > temp;j--){
                    arr[j+1] = arr[j];
                }
                arr[j+1] = temp;
            }
        }
    }
}
